"""
@author: yinjx
@file: lianxi-homecaidaxiao.py
@time: 2023/4/16 9:20
"""
##猜拳游戏  用户创建房间 选择加入房间  房间里要等于两个人 就可以游戏了 两个人互相猜拳   ab 两人 随机出剪刀石头布  输的人扣一百金豆  按任意键随机开始
#直到金豆输完 或者直接q退出  存在的类：房间类 ：属性：房间id  房间里面的人 方法：加入房间  退出房间     用户类  属性：用户id  京豆  用户属于哪个房间  方法：猜拳

#自定义一个房间  --》里面有房间号  和哪些人
#定义一个字典 里面存储的是对应的房房间号
import random
home = {    #房间里面的 0 代表空 1表示 存在一个玩家
    "home1": {"game_player1": 0, "game_player2": 1},
    "home2": {"game_player1": 0, "game_player2": 1},
    "home3": {"game_player1": 0, "game_player2": 0},
    "home4": {"game_player1": 1, "game_player2": 1},
    "home5": {"game_player1": 0, "game_player2": 1},
    "home6": {"game_player1": 0, "game_player2": 1},
    "home7": {"game_player1": 0, "game_player2": 1},
    "home8": {"game_player1": 0, "game_player2": 1},
    "home9": {"game_player1": 1, "game_player2": 0},
    "home10": {"game_player1": 1, "game_player2": 1}
}

class User:
    def __init__(self, name):   # 所属的home先暂定
        self.name = name
        self.gold_bean = 1000
        # self.belong_home = belong_home




class Home:
    def __init__(self, home_id,username):  # 所属的home先暂定
        self.home_id = home_id
        self.username = username
    def Judge_home(self,home_id):
        if home_id in home:
            num1 = int(home[home_id]["game_player1"])
            num2 = int(home[home_id]["game_player2"])
            if num1 + num2 == 2:
                print("房间已满")
            else:
                print("房间可加入，是否加入，输入i加入，r进行重新选择home,q退出程序")
    def Join_home(self,home_id):
        if int(home[home_id]["game_player1"]) + int(home[home_id]["game_player2"]) == 0:
            print("需要等待下一个玩家的加入才可进行游戏")
            home[home_id]["game_player1"] = 1
        else:   # int(home[home_id]["game_player1"]) + int(home[home_id]["game_player2"]) == 1
            print("进入游戏")
            if int(home[home_id]["game_player1"]) == 1:
                home[home_id]["game_player2"] = 1
            else:
                home[home_id]["game_player1"] = 1
    # def Play_game(self):


def Play_game(gold_bean):
    print(f"你现有的金豆为{user.gold_bean}")
    #d1 = {1: "石头", 2: "剪刀", 3: "布"}
    a = random.randint(1, 3)
    b = random.randint(1, 3)
    while 1:
        if a == b:
            print("平局！")
            continue
        else:
            if (a == 1 and b == 2) or (a == 2 and b == 3) or (a == 3 and b == 1):
                gold_bean = gold_bean + 100
                print("赢了！")
            else:
                gold_bean = gold_bean - 100
                print("输了！")
        print(f"{gold_bean}")
        if gold_bean < 100:
            print("余额不足，欢迎下次再来")
            break
        a = input("任意键继续，按q退出")
        if a == 'q':
            print(f"你的余额为{gold_bean}")
            break
        else:
            continue




while 1:
    print("欢迎来到猜拳系统")
    print("输入name,并且选择房间")
    name = input("请输入你的name")
    user = User(name)
    # home_id = input("可被选择的房间home1~home10")
    # choice = Home(home_id, name)
    # choice.Judge_home(home_id)
    while 1:
        home_id = input("可被选择的房间home1~home10")
        choice = Home(home_id, name)
        if home_id in home:
            choice.Judge_home(home_id)
        else:
            print("输入有误")
            continue
        choice_join = input("")
        if choice_join == 'i':
            choice.Join_home(home_id)
            print(f"你现有的金豆为{user.gold_bean}")
            print("游戏说明：1代表石头，2代表剪刀，3代表布，0结束游戏")
            Play_game(user.gold_bean)
        elif choice_join == 'r':
            continue
        elif choice_join == 'q':
            break
        else:
            print("输入有误,请重新输入")
            continue














